package com.example.explainus;

import java.util.Locale;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class LanguageActivity extends Activity
{

	private Button bEng;
	private Button bRus;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_changelanguage);
		bEng = (Button)findViewById(R.id.bEng);
		bEng.setOnClickListener(onClick);
		bRus = (Button)findViewById(R.id.bRus);
		bRus.setOnClickListener(onClick);
	}
	private OnClickListener onClick = new OnClickListener() 
	{
		
		@Override
		public void onClick(View v) {
			switch(v.getId())
			{
				case R.id.bEng:
				{
					try
					{
						Locale loc = new Locale("en_US");
						Locale.setDefault(loc);
						Configuration config = new Configuration();
						config.locale = loc;
					    getApplicationContext().getResources().updateConfiguration(config, null);
					    bEng.setBackgroundResource(R.drawable.button_boarder_change);
					    Intent back = new Intent(LanguageActivity.this, MainActivity.class);
					    startActivity(back);
					    finish();
					}
					catch(Exception ex)
					{
						
					}
					finally
					{
						
					}
				}
				break;
				case R.id.bRus:
				{
					try
					{
						Locale loc = new Locale("ru_RU");
						Locale.setDefault(loc);
						Configuration config = new Configuration();
						config.locale = loc;
					    getApplicationContext().getResources().updateConfiguration(config, null);
					    bRus.setBackgroundResource(R.drawable.button_boarder_change);
					    Intent back = new Intent(LanguageActivity.this, MainActivity.class);
					    startActivity(back);
					    finish();
					}
					catch (Exception ex)
					{
						
					}
					finally
					{
						
					}
				}
				break;
				default : break;
			}
			
		}
	};
	

}
